package com.ruoyi.exam.controller.admin;

import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.result.Result;
import com.ruoyi.exam.service.IExamPaperAnswerService;
import com.ruoyi.exam.service.IExamPaperQuestionCustomerAnswerService;
import com.ruoyi.exam.service.IExamPaperService;
import com.ruoyi.exam.service.IQuestionService;
import com.ruoyi.exam.utils.DateTimeUtil;
import com.ruoyi.exam.viewmodel.admin.dashboard.IndexVM;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;

@Api(tags = "admin首页信息")
@RestController("AdminDashboardController")
@RequestMapping(value = "/api/admin/dashboard")
public class DashboardController extends BaseController {

    @Resource(name = "ExamPaperServiceImpl")
    private IExamPaperService examPaperService;

    @Resource(name = "QuestionServiceImpl")
    private IQuestionService questionService;

    @Resource(name = "ExamPaperAnswerServiceImpl")
    private IExamPaperAnswerService examPaperAnswerService;

    @Resource(name = "ExamPaperQuestionCustomerAnswerServiceImpl")
    private IExamPaperQuestionCustomerAnswerService examPaperQuestionCustomerAnswerService;

    @ApiOperation(value = "首页查询", notes = "admin首页信息")
    @GetMapping(value = "/index")
    public Result<IndexVM> Index() {
        IndexVM vm = new IndexVM();

        Integer examPaperCount = examPaperService.selectAllCount();
        Integer questionCount = questionService.selectAllCount();
        Integer doExamPaperCount = examPaperAnswerService.selectAllCount();
        Integer doQuestionCount = examPaperQuestionCustomerAnswerService.selectAllCount();

        vm.setExamPaperCount(examPaperCount);
        vm.setQuestionCount(questionCount);
        vm.setDoExamPaperCount(doExamPaperCount);
        vm.setDoQuestionCount(doQuestionCount);

        List<Integer> mothDayUserActionValue = new ArrayList<>();
        List<Integer> mothDayDoExamQuestionValue = examPaperQuestionCustomerAnswerService.selectMothCount();
        vm.setMothDayUserActionValue(mothDayUserActionValue);
        vm.setMothDayDoExamQuestionValue(mothDayDoExamQuestionValue);

        vm.setMothDayText(DateTimeUtil.MothDay());
        return Result.ok(vm);
    }
}
